import Vue from 'vue'
import Vuex from 'vuex'
import mutations from "./mutations";
import actions from "./actions";
import getters from "./getters";
import moduleA from "./modules/moduleA";
import moduleB from "./modules/moduleB";


// 1.安装插件
Vue.use(Vuex)

const state = {
  counter:100,
  students:[
    {id:110,name:'阿絮',age:30},
    {id:111,name:'老温',age:29},
    {id:112,name:'张哲瀚',age:19},
    {id:113,name:'龚俊',age:18},
  ],
  info:{name:'发财树',age:24,height:1.86}
}

// 2.创建store对象
const store=new Vuex.Store({
  state,
  mutations,
  actions,
  getters,
  modules:{
    //modules里的a模块里的state，最终会放到state里面，所有展示数据的时候使用$store.state.a.name
    a: moduleA,
    b: moduleB
  }
})

//3.导出store对象
export default store



// 扩充知识点：对象的解构
const obj={
  name:'瀚瀚',
  age:20,
  height:1.81,
  lover:'俊俊'
}
// 根据名字取出，顺序不影响，也可以只取一部分
const {name,height,age} = obj
console.log(name); // 瀚瀚
console.log(age); // 20

// 扩充知识点：数组的解构, 很少用
const names = ['moon','one','baby']
const [name1,name2,name3] = names
console.log(name1);
console.log(name1);